import numpy as np
from sklearn.cluster import KMeans
import matplotlib.pyplot as plt 

n = 100# the number of the sample
x = np.array([[np.random.randint(n) for i in range(n)]])
y = np.array([[np.random.randint(n) for i in range(n)]])

x = x.T
y = y.T

X = np.hstack((x,y))
print(X)



plt.scatter(x,y)

clf = KMeans(n_clusters = 3)#n_clusters is the number of the clusters
clf.fit(X)# classify

centers = clf.cluster_centers_# the center of the cluster
labels = clf.labels_ #mark the sample
print('center',centers)
print('labels',labels)
plt.scatter(centers[:,0], centers[:,1])

plt.show()


